package com.HuiShou.controller.common;


import com.HuiShou.service.impl.DetectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/api/detection")
public class DetectionController {

    @Autowired
    private DetectionService detectionService;
    /**
     * 文件上传检测接口
     * @param imageFile 上传的图片文件
     * @return 包含检测结果和可视化图片的响应
     */
    @PostMapping("/detect")
    @PreAuthorize("@ss.hasPermi('api:detection:detect')")
    public ResponseEntity<?> detectImageUpload(@RequestParam("file") MultipartFile imageFile) {
        try {
            // 调用改造后的检测方法
            Map<String, Object> result = detectionService.detectImage(imageFile);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.internalServerError()
                    .body(Map.of(
                            "errorCode", "DETECTION_FAILED",
                            "message", e.getMessage()
                    ));
        }
    }
}
